;; install MELPA ELPA
;; method 1---------------------------------------------
;;(require 'package) ;; You might already have this line
;;(add-to-list 'package-archives
;;             '("melpa" . "https://melpa.org/packages/"))
;;(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
;;  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
;; (package-initialize) ;; You might already have this line

;; method 2-------------------------------------------


;; ------------------------插件初始化-----------------------
;;(package-initialize)
(add-to-list 'load-path "~/.emacs.d/lisp/") ;;添加路径
;; Packages Managerment
;; -------------------------
(require 'init-packages)




;; Find Executable Path on OS X
(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))

;;------------------end------------------

;; 默认全屏
(setq initial-frame-alist (quote ((fullscreen . maximized))))

;; 自动括号匹配
(add-hook 'emacs-lisp-mode-hook 'show-paren-mode)

;;高亮当行
(global-hl-line-mode 1)

;; 加载主题 monokai 

(load-theme 'monokai 1)

;;关闭状态栏
(tool-bar-mode -1)

;;关闭文件滑动控件
(scroll-bar-mode -1)

;;显示行号
(global-linum-mode 1)

;;更改光标样式
(setq inhibit-splash-screen -1)

;; 关闭光标样式
(setq cursor-type 'bar)

;;关闭缩进
;;(electric-indent-mode -1)

;; 显示字体大小 16px
(set-face-attribute 'default nil :height 160)

;; 快速打开配置文件
(defun open-init-file()
  (interactive)
  (find-file "~/.emac.d/init.el")
  )

;; 将 open init file 函数绑定到F2键上
(global-set-key (kbd "<f2>") 'open-init-file)

;; 开启全局Company补全
(global-company-mode 1)

;; 关闭自动生成备份文件
;; (setq make-backup-file nil)
;; (setq auto-save-default nil)

;; 自动加载外部修过的文件
(global-auto-revert-mode 1)

;; 关闭警报音
(setq ring-bell-function 'ignore)



;;打开最近编辑过的文件
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-item 10)


;; 这个快捷键绑定可以用之后的插件 counsel 代替
;; (global-set-key (kbd "C-x C-r") 'recentf-open-files)


;; 代码缩进 及 按键绑定
(defun indent-buffer()
  (interactive)
  (indent-region (point-min) (point-max)))

(defun indent-region-or-buffer()
  (interactive)
  (save-excursion
    (if (region-active-p)
	(progn
	  (indent-region (region-beginning) (region-end))
	  (message "Indent selected region."))
      (progn
	(indent-buffer)
	(message "Indent buffer.")))))

(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)


;; 缩写补全

(abbrev-mode 1)
(define-abbrev-table 'global-abbrev-table '(
					    ;; tanpengcd@gmail.com
					    ("tp@" "tanpengcd@gmail.com")

					    ))
;; Hippie 补全 及绑定按键

(setq hippie-expand-try-function-list '(try-expand-debbrev
					try-expand-debbrev-all-buffers
					try-expand-debbrev-from-kill
					try-complete-file-name-partially
					try-complete-file-name
					try-expand-all-abbrevs
					try-expand-list
					try-expand-line
					try-complete-lisp-symbol-partially
					try-complete-lisp-symbol))
(global-set-key (kbd "s-/") 'hippie-expand)


;;---------------------- JavaScrip IDE -----------------
(setq auto-mode-alist
      (append
       '(("\\.js\\'" . js2-mode))
       auto-mode-alist)
      )

